package com.jiaai.web.zfp_back.gift;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.exception.ServerException;
import com.jiaai.guard.IGuardApi;
import com.jiaai.guard.model.GuardVo;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * class_name:ZBGuardController
 * describe:TODO
 * create_user:张昉平
 * create_date:2017/12/27
 * create_date:18:10
 */
@RestController
@RequestMapping("/api/v1/admin/guard")
public class ZBGuardController {

    @Reference
    private IGuardApi iGuardApi;
//
//    @RequestMapping("/list")
//    public Object list(@RequestParam Integer curr)throws ServerException {
//        return  RestResultGenerator.genSuccessResult(iGuardApi.getAll(curr));
//    }
//
//    @PostMapping("/saveoredit")
//    public Object saveOrEdit(@RequestBody GuardVO guardVO)throws ServerException {
//        iGuardApi.saveOrEdit(guardVO);
//        return  RestResultGenerator.genSuccessResult("操作成功");
//    }
//
//    @RequestMapping("/delete/{id}/{flag}")
//    public Object delete(@PathVariable("id") Integer id, @PathVariable("flag") Integer flag)throws ServerException {
//        iGuardApi.delete(id, flag);
//        return  RestResultGenerator.genSuccessResult("操作成功");
//    }

    @RequestMapping("/list")
    public Object list(GuardVo guardVo)throws ServerException {
        try {
            return  RestResultGenerator.genSuccessResult(iGuardApi.findByAll(guardVo));
        } catch (Exception e) {
            throw new ServerException("查询失敗");
        }
    }

    @PostMapping("/add")
    public Object pushMessage(@RequestBody GuardVo guardVo) throws Exception{
        try {
            iGuardApi.editGuard(guardVo);
            return RestResultGenerator.genSuccessResult("添加成功");
        } catch (Exception e) {
            return RestResultGenerator.genErrorResult("添加失败");
        }

    }
}
